package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.qf.dao.Sys_carDao;
import com.qf.pojo.Sys_car;
import com.qf.service.Sys_carService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Sys_carServiceImpl implements Sys_carService {

    @Autowired
    Sys_carDao sys_carDao;


    @Override
    public BaseResult addCar(Sys_car sysCar) {
        int i = sys_carDao.addCar(sysCar);
        //声明返回值
        BaseResult baseResult = new BaseResult();
        if(i>0){
            baseResult.setCode(0);
            baseResult.setMessage("添加成功");
            return baseResult;
        }else{
            baseResult.setCode(1);
            baseResult.setMessage("添加失败");
            return baseResult;
        }
    }

    @Override
    public BaseResult delCarById(Integer id) {
        int i = sys_carDao.delCarById(id);
        //声明返回值
        BaseResult baseResult = new BaseResult();
        if(i>0){
            baseResult.setCode(0);
            baseResult.setMessage("删除成功");
            return baseResult;
        }else{
            baseResult.setCode(1);
            baseResult.setMessage("删除失败");
            return baseResult;
        }
    }

    @Override
    public BaseResult updateById(Sys_car sysCar) {
        int i = sys_carDao.updateById(sysCar);
        //声明返回值
        BaseResult baseResult = new BaseResult();
        if(i>0){
            baseResult.setCode(0);
            baseResult.setMessage("修改成功");
            return baseResult;
        }else{
            baseResult.setCode(1);
            baseResult.setMessage("修改失败");
            return baseResult;
        }
    }

    @Override
    public Sys_car findCarBycId(Integer cId) {
        return sys_carDao.findcarBycId(cId);
    }

    @Override
    public List<Sys_car> fingCarByName(Integer page, Integer size, String name) {
        PageHelper.startPage(page,size);
        List<Sys_car> carLists = sys_carDao.fingCarByName(name);
        return carLists;
    }

    @Override
    public List<Sys_car> fingCarByPrice(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Sys_car> carLists = sys_carDao.fingCarByPrice();
        return carLists;
    }

    @Override
    public List<Sys_car> fingCarByNumber(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Sys_car> carLists = sys_carDao.fingCarByNumber();
        return carLists;
    }

}
